﻿#ifndef __SSCLOCKWHEEL_H__
#define __SSCLOCKWHEEL_H__
#include "ssClockSolt.h"
#include "../ssTimer.h"
#include "../../thread/ssThreadBase.h"
#include "../../thread/threadLock/ssThreadLock.h"
#include "../../tools/ssIDAlloter.h"
#include "../ssTimerDispatch.h"

namespace StarSeeker
{
//计时器距离当前时间的秒数不能超过2的32次方，时间戳必须大于当前时间
class ssClockWheel : public ssTimerDispatch
{
	union Tick_u
	{
		u32	tick;
		struct { u8 _l1, _l2, _l3, _l4; };
	};
public:
	ssClockWheel();
	~ssClockWheel();
	//添加计时器
	u32 AddTimer(u32 msgType, u64 timestamp, u32 interval, ulint p1, ulint p2);
	u32 AddTimer(u32 msgType, u32 interval, ulint param1, ulint param2);
	//删除计时器，靠遍历的效率很低
	void RemoveTimer(u32 timerId);
	//启动半点计时器
	void StartHalfTimer();
	//更新计时器
	void Update();
protected:
	//时钟加一
	void AddTick();
	//重新添加
	void Readd(ssTimer_s& msg, u32 interval);
protected:
	ssClockSolt				m_solt[SS_CLOCK_SOLT];
	Tick_u					m_tick;
	ssCumulationID<u32>		m_ids;
	std::list<ssTimer_s>	m_temp;
public:
	ssDiffTimer				m_timer;
};

}
#endif
